//
//  HomeLocationHeaderItemView.swift
//  HomeLocationHeaderItemView
//
//  Created by Ben on 2021/9/18.
//

import Foundation
import SwiftUI

struct HomeLocationHeaderItemView<Content: View>: View {
    
    private var title: String
    private var subTitle: String
    private var subTitleColor: Color
    private var bgColor: Color
    private var content: () -> Content
    
    init(title: String, subTitle: String, subTitleColor: Color, bgColor: Color, @ViewBuilder content: @escaping () -> Content) {
        self.title = title
        self.subTitle = subTitle
        self.subTitleColor = subTitleColor
        self.bgColor = bgColor
        self.content = content
    }
     
    var body: some View {
        VStack {
            VStack(alignment: .leading, spacing: 4) {
                Text(title)
                    .font(.system(size: 16, weight: .bold))
                    
                Text(subTitle)
                    .font(.system(size: 12, weight: .semibold))
                    .foregroundColor(subTitleColor)
            }
            .frame(maxWidth: .infinity, alignment: .leading)
            
            // 其他内容
            content()
                .frame(height: 60)
                .padding(.top, 10)
        }
        .padding(.horizontal, 8)
        .padding(.vertical, 8)
        .background(
            RoundedRectangle(cornerRadius: 10)
                .fill(bgColor)
        )
    }
}

struct HomeLocationHeaderItemView_Preview: PreviewProvider {
    static var previews: some View {
        HomeLocationHeaderItemView(title: "找人帮忙", subTitle: "持证服务更靠谱", subTitleColor: Color(hex: 0x2EAE5E), bgColor: Color(hex: 0xF2FAF8)) {
            Color.random()
        }
    }
}
